home *** CD-ROM | disk | FTP | other *** search
/ Champak 66 / Vol 66.iso / games / bob_espo.swf / scripts / __Packages / CTRLGame.as < prev    next >
Encoding:
Text File  |  2013-04-24  |  13.6 KB  |  461 lines

  1. class CTRLGame
  2. {
  3.    var mcRef;
  4.    var nScore;
  5.    var nCurrentLevel;
  6.    var oGenerator;
  7.    var oAtlantisBus;
  8.    var oCenterScreen;
  9.    var aWalls;
  10.    var aDirtWalls;
  11.    var aJellys;
  12.    var aAlguaes;
  13.    var nNbPushBusSandyLeft;
  14.    var nSongsNumber;
  15.    var aItems;
  16.    static var oRef;
  17.    static var nOUT_POS_BTN_CACHE = -400;
  18.    static var nPOWERUP_BONUS_POINTS = 0;
  19.    static var nPOWERUP_GOOD_NOTE = 1;
  20.    static var nPOWERUP_FALSE_NOTE = 2;
  21.    static var nTURN_WALL = 0;
  22.    static var nTURN_WALL_INVERSE = 1;
  23.    static var nSLIDE_WALL_H = 2;
  24.    static var nSLIDE_WALL_V = 3;
  25.    static var nREVOLVER_WALL = 4;
  26.    static var nDIR_LEFT = 0;
  27.    static var nDIR_UP = 1;
  28.    static var nDIR_RIGHT = 2;
  29.    static var nDIR_DOWN = 3;
  30.    static var nLEVEL1 = 1;
  31.    static var nLEVEL2 = 2;
  32.    static var nDUMMY_DEPTH = 999999;
  33.    static var nMIN_DEPTH = 100012;
  34.    static var nDEPTH_FACTOR = 100;
  35.    static var nDIRT_WALL_ADD = 1;
  36.    static var nMOVING_WALL_ADD = 25;
  37.    static var nALGAE_ADD = 50;
  38.    static var nBUS_ADD = 76;
  39.    static var nJELLYFISH_ADD = 100;
  40.    static var nNB_THROW_SOUNDS = 5;
  41.    function CTRLGame(_mcRef, _nScore, _nLevel)
  42.    {
  43.       this.mcRef = _mcRef;
  44.       CTRLGame.oRef = this;
  45.       this.nScore = _nScore;
  46.       this.nCurrentLevel = _nLevel;
  47.       this.initLevel();
  48.    }
  49.    function cleanUp()
  50.    {
  51.       this.oGenerator.cleanUp();
  52.       this.oAtlantisBus.cleanUp();
  53.       this.oCenterScreen.cleanUp();
  54.       for(var i in this.aWalls)
  55.       {
  56.          this.aWalls[i].cleanUp();
  57.       }
  58.       for(var i in this.aDirtWalls)
  59.       {
  60.          for(var j in this.aDirtWalls[i])
  61.          {
  62.             this.aDirtWalls[i][j].cleanUp();
  63.          }
  64.       }
  65.       for(var i in this.aJellys)
  66.       {
  67.          this.aJellys[i].cleanUp();
  68.       }
  69.       for(var i in this.aAlguaes)
  70.       {
  71.          for(var j in this.aAlguaes[i])
  72.          {
  73.             this.aAlguaes[i][j].cleanUp();
  74.          }
  75.       }
  76.       delete this.oGenerator;
  77.       delete this.oAtlantisBus;
  78.       delete this.oCenterScreen;
  79.    }
  80.    function addObjectViaDummy(_mcDummy)
  81.    {
  82.       var _loc3_ = new Object();
  83.       _loc3_.x = 0;
  84.       _loc3_.y = 0;
  85.       _loc3_.x = _mcDummy._x;
  86.       _loc3_.y = _mcDummy._y;
  87.       _mcDummy._parent.localToGlobal(_loc3_);
  88.       _mcDummy.swapDepths(CTRLGame.nDUMMY_DEPTH);
  89.       _mcDummy.removeMovieClip();
  90.       return _loc3_;
  91.    }
  92.    function countdownPushBusGames()
  93.    {
  94.       if(this.nNbPushBusSandyLeft > 0)
  95.       {
  96.          this.nNbPushBusSandyLeft = this.nNbPushBusSandyLeft - 1;
  97.       }
  98.    }
  99.    function modifyTime(_nNewValue)
  100.    {
  101.       this.nSongsNumber = _nNewValue;
  102.    }
  103.    function blockEvents()
  104.    {
  105.       this.mcRef.mcCache._y = 0;
  106.       this.mcRef.mcShadow._visible = true;
  107.    }
  108.    function unBlockEvents()
  109.    {
  110.       this.mcRef.mcCache._y = CTRLGame.nOUT_POS_BTN_CACHE;
  111.       this.mcRef.mcShadow._visible = false;
  112.    }
  113.    function addToScore(_nNumber)
  114.    {
  115.       this.nScore += _nNumber;
  116.       Main.getRef().updateScoreField();
  117.    }
  118.    function substractToScore(_nNumber)
  119.    {
  120.       this.nScore -= _nNumber;
  121.       Main.getRef().updateScoreField();
  122.    }
  123.    function calculateDepth(_nY, _nAdd)
  124.    {
  125.       var _loc4_ = Math.round(_nY) * CTRLGame.nDEPTH_FACTOR + _nAdd + CTRLGame.nMIN_DEPTH;
  126.       return _loc4_;
  127.    }
  128.    function stopAnimElements()
  129.    {
  130.       for(var i in this.aDirtWalls)
  131.       {
  132.          for(var j in this.aDirtWalls[i])
  133.          {
  134.             this.aDirtWalls[i][j].doPause();
  135.          }
  136.       }
  137.       for(var i in this.aJellys)
  138.       {
  139.          this.aJellys[i].doPause();
  140.       }
  141.       for(var i in this.aAlguaes)
  142.       {
  143.          for(var j in this.aAlguaes[i])
  144.          {
  145.             this.aAlguaes[i][j].doPause();
  146.          }
  147.       }
  148.       this.oAtlantisBus.doPause();
  149.    }
  150.    function resumeAnimElements()
  151.    {
  152.       for(var i in this.aDirtWalls)
  153.       {
  154.          for(var j in this.aDirtWalls[i])
  155.          {
  156.             this.aDirtWalls[i][j].resumeAnim();
  157.          }
  158.       }
  159.       for(var i in this.aJellys)
  160.       {
  161.          this.aJellys[i].resumeAnim();
  162.       }
  163.       for(var i in this.aAlguaes)
  164.       {
  165.          for(var j in this.aAlguaes[i])
  166.          {
  167.             this.aAlguaes[i][j].resumeAnim();
  168.          }
  169.       }
  170.       this.oAtlantisBus.resumeAnim();
  171.    }
  172.    function addPowerUp(_nType, _mcItem)
  173.    {
  174.       var _loc4_ = new Object();
  175.       _loc4_.mcRef = _mcItem;
  176.       _mcItem._xscale = _mcItem._parent._parent._xscale;
  177.       _loc4_.nType = _nType;
  178.       var _loc5_ = this.oGenerator.getTabIndexByName(_mcItem._parent._parent._name);
  179.       this.aItems[_loc5_].push(_loc4_);
  180.    }
  181.    function addDirtWall(_mcDummy)
  182.    {
  183.       var _loc3_ = this.oGenerator.getTabIndexByName(_mcDummy._parent._parent._name);
  184.       var _loc4_ = this.addObjectViaDummy(_mcDummy);
  185.       this.aDirtWalls[_loc3_].push(new DirtWall(_loc4_.x,_loc4_.y));
  186.    }
  187.    function addJellyFish(_mcDummy)
  188.    {
  189.       var _loc3_ = this.addObjectViaDummy(_mcDummy);
  190.       this.aJellys.push(new RoamingJellyFish(_loc3_.x,_loc3_.y));
  191.    }
  192.    function addAlgae(_mcDummy)
  193.    {
  194.       var _loc3_ = this.oGenerator.getTabIndexByName(_mcDummy._parent._parent._name);
  195.       var _loc4_ = this.addObjectViaDummy(_mcDummy);
  196.       this.aAlguaes[_loc3_].push(new Algae(_loc4_.x,_loc4_.y));
  197.    }
  198.    function addActionWall(_nType, _mcDummy, _xScl)
  199.    {
  200.       var _loc5_ = this.addObjectViaDummy(_mcDummy);
  201.       this.aWalls.push(new ActionWall(_nType,_loc5_.x,_loc5_.y,_xScl));
  202.    }
  203.    function checkPowerUps()
  204.    {
  205.       var _loc2_ = this.oAtlantisBus.mcRef;
  206.       var _loc3_ = this.oGenerator.getTabIndex(_loc2_._x,_loc2_._y);
  207.       var _loc4_ = this.aItems[_loc3_];
  208.       for(var i in _loc4_)
  209.       {
  210.          if(_loc4_[i].mcRef.hitTest(_loc2_._x,_loc2_._y,true))
  211.          {
  212.             this.activatePowerUp(_loc4_[i].nType,_loc4_[i].mcRef);
  213.             delete _loc4_[i];
  214.             _loc4_.splice(Number(i),1);
  215.             break;
  216.          }
  217.       }
  218.    }
  219.    function checkDirtWalls()
  220.    {
  221.       var _loc2_ = this.oAtlantisBus.mcRef;
  222.       var _loc3_ = this.oGenerator.getTabIndex(_loc2_._x,_loc2_._y);
  223.       var _loc4_ = this.aDirtWalls[_loc3_];
  224.       for(var i in _loc4_)
  225.       {
  226.          if(_loc4_[i].mcRef.mcHit.hitTest(_loc2_.mcHit))
  227.          {
  228.             this.oCenterScreen.startBreakTheWall(_loc4_[i]);
  229.             _loc4_.splice(Number(i),1);
  230.             break;
  231.          }
  232.       }
  233.    }
  234.    function checkJellys()
  235.    {
  236.       var _loc2_ = this.oAtlantisBus.mcRef;
  237.       for(var i in this.aJellys)
  238.       {
  239.          if(this.aJellys[i].mcRef.mcHit.hitTest(_loc2_._x,_loc2_._y,true))
  240.          {
  241.             this.aJellys[i].stopRoaming();
  242.             this.oCenterScreen.startJellyFishSwarm(this.aJellys[i]);
  243.             this.aJellys.splice(Number(i),1);
  244.             break;
  245.          }
  246.       }
  247.    }
  248.    function checkAlgaes()
  249.    {
  250.       var _loc2_ = this.oAtlantisBus.mcRef;
  251.       var _loc3_ = this.oGenerator.getTabIndex(_loc2_._x,_loc2_._y);
  252.       var _loc4_ = this.aAlguaes[_loc3_];
  253.       for(var i in this.aAlguaes)
  254.       {
  255.          if(_loc4_[i].mcRef.mcHit.hitTest(_loc2_._x,_loc2_._y,true))
  256.          {
  257.             _loc4_[i].catchBus();
  258.             var _loc5_ = true;
  259.             if(this.nNbPushBusSandyLeft <= 0)
  260.             {
  261.                _loc5_ = false;
  262.             }
  263.             this.oCenterScreen.startPushTheBus(_loc4_[i],_loc5_);
  264.             _loc4_.splice(Number(i),1);
  265.             break;
  266.          }
  267.       }
  268.    }
  269.    function checkFinish()
  270.    {
  271.       var _loc2_ = this.oAtlantisBus.mcRef;
  272.       if(this.mcRef.mcStart.piece.mcFinish.hitTest(this.oAtlantisBus.mcRef._x,this.oAtlantisBus.mcRef._y,true) && !Main.getRef().Finished)
  273.       {
  274.          Main.getRef().winGame();
  275.       }
  276.    }
  277.    function isOkayToTurn(_mcHit)
  278.    {
  279.       var _loc3_ = true;
  280.       if(_mcHit.hitTest(this.oAtlantisBus.mcRef._x,this.oAtlantisBus.mcRef._y,true) || _mcHit.hitTest(this.oAtlantisBus.getMiCasePos().x,this.oAtlantisBus.getMiCasePos().y,true))
  281.       {
  282.          _loc3_ = false;
  283.       }
  284.       if(_loc3_)
  285.       {
  286.          for(var i in this.aJellys)
  287.          {
  288.             if(_mcHit.hitTest(this.aJellys[i].mcRef._x,this.aJellys[i].mcRef._y,true) || _mcHit.hitTest(this.aJellys[i].getMiCasePos().x,this.aJellys[i].getMiCasePos().y,true))
  289.             {
  290.                _loc3_ = false;
  291.                break;
  292.             }
  293.          }
  294.       }
  295.       return _loc3_;
  296.    }
  297.    function isOkayToTurnRevolver(_mcHit, _mcHitMore)
  298.    {
  299.       var _loc4_ = true;
  300.       if(_mcHit.hitTest(this.oAtlantisBus.mcRef._x,this.oAtlantisBus.mcRef._y,true) || (_mcHit.hitTest(this.oAtlantisBus.getMiCasePos().x,this.oAtlantisBus.getMiCasePos().y,true) || (_mcHitMore.hitTest(this.oAtlantisBus.mcRef._x,this.oAtlantisBus.mcRef._y,true) || _mcHitMore.hitTest(this.oAtlantisBus.getMiCasePos().x,this.oAtlantisBus.getMiCasePos().y,true))))
  301.       {
  302.          _loc4_ = false;
  303.       }
  304.       if(_loc4_)
  305.       {
  306.          for(var i in this.aJellys)
  307.          {
  308.             if(_mcHit.hitTest(this.aJellys[i].mcRef._x,this.aJellys[i].mcRef._y,true) || (_mcHit.hitTest(this.aJellys[i].getMiCasePos().x,this.aJellys[i].getMiCasePos().y,true) || (_mcHitMore.hitTest(this.aJellys[i].mcRef._x,this.aJellys[i].mcRef._y,true) || _mcHitMore.hitTest(this.aJellys[i].getMiCasePos().x,this.aJellys[i].getMiCasePos().y,true))))
  309.             {
  310.                _loc4_ = false;
  311.                break;
  312.             }
  313.          }
  314.       }
  315.       return _loc4_;
  316.    }
  317.    function isTouchingWall(_nFutureX, _nFutureY)
  318.    {
  319.       var _loc4_ = false;
  320.       for(var i in this.aWalls)
  321.       {
  322.          var _loc5_ = this.aWalls[i];
  323.          if(_loc5_.Type == CTRLGame.nREVOLVER_WALL)
  324.          {
  325.             if(_loc5_.Ref.mcHit.hitTest(_nFutureX,_nFutureY,true) || _loc5_.Ref.mcHitMore.hitTest(_nFutureX,_nFutureY,true))
  326.             {
  327.                _loc4_ = true;
  328.                break;
  329.             }
  330.          }
  331.          else if(_loc5_.Ref.mcHit.hitTest(_nFutureX,_nFutureY,true))
  332.          {
  333.             _loc4_ = true;
  334.             break;
  335.          }
  336.       }
  337.       return _loc4_;
  338.    }
  339.    function isJellyTouchingDirtWall(_nFutureX, _nFutureY)
  340.    {
  341.       var _loc4_ = false;
  342.       var _loc5_ = this.oGenerator.getTabIndex(_nFutureX,_nFutureY);
  343.       var _loc6_ = this.aDirtWalls[_loc5_];
  344.       for(var i in _loc6_)
  345.       {
  346.          if(_loc6_[i].mcRef.mcHit.hitTest(_nFutureX,_nFutureY,true))
  347.          {
  348.             _loc4_ = true;
  349.             break;
  350.          }
  351.       }
  352.       return _loc4_;
  353.    }
  354.    function isJellyTouchingAlguae(_nFutureX, _nFutureY)
  355.    {
  356.       var _loc4_ = false;
  357.       var _loc5_ = this.oGenerator.getTabIndex(_nFutureX,_nFutureY);
  358.       var _loc6_ = this.aAlguaes[_loc5_];
  359.       for(var i in _loc6_)
  360.       {
  361.          if(_loc6_[i].mcRef.mcHit.hitTest(_nFutureX,_nFutureY,true))
  362.          {
  363.             _loc4_ = true;
  364.             break;
  365.          }
  366.       }
  367.       return _loc4_;
  368.    }
  369.    function isJellyTouchingJelly(_nFutureX, _nFutureY, _oJelly)
  370.    {
  371.       var _loc5_ = false;
  372.       for(var i in this.aJellys)
  373.       {
  374.          if(this.aJellys[i] != _oJelly)
  375.          {
  376.             if(this.aJellys[i].mcRef.mcHit.hitTest(_nFutureX,_nFutureY,true))
  377.             {
  378.                _loc5_ = true;
  379.                break;
  380.             }
  381.          }
  382.       }
  383.       return _loc5_;
  384.    }
  385.    function get Screen()
  386.    {
  387.       return this.oCenterScreen;
  388.    }
  389.    function get Bus()
  390.    {
  391.       return this.oAtlantisBus;
  392.    }
  393.    function get Maze()
  394.    {
  395.       return this.oGenerator;
  396.    }
  397.    function get Songs()
  398.    {
  399.       return this.nSongsNumber;
  400.    }
  401.    function get Level()
  402.    {
  403.       return this.nCurrentLevel;
  404.    }
  405.    function get Score()
  406.    {
  407.       return this.nScore;
  408.    }
  409.    static function getRef()
  410.    {
  411.       return CTRLGame.oRef;
  412.    }
  413.    function activatePowerUp(_nType, _mcPowerUp)
  414.    {
  415.       switch(_nType)
  416.       {
  417.          case CTRLGame.nPOWERUP_BONUS_POINTS:
  418.             Controller.getRef().getSounds().playSound("GoodPowerUp_Collect",Controller.nSFX_VOLUME,1);
  419.             this.addToScore(LD.nBONUSPOINTS);
  420.             _mcPowerUp.swapDepths(7777);
  421.             _mcPowerUp.removeMovieClip();
  422.             break;
  423.          case CTRLGame.nPOWERUP_FALSE_NOTE:
  424.             Controller.getRef().getSounds().playSound("BadPowerUp_Collect",Controller.nSFX_VOLUME,1);
  425.             CTRLGame.getRef().Screen.getInterface().setToLife(LD.nFALSE_NOTE_VALUE);
  426.             _mcPowerUp.swapDepths(7777);
  427.             _mcPowerUp.removeMovieClip();
  428.             break;
  429.          case CTRLGame.nPOWERUP_GOOD_NOTE:
  430.             Controller.getRef().getSounds().playSound("GoodPowerUp_Collect",Controller.nSFX_VOLUME,1);
  431.             CTRLGame.getRef().Screen.getInterface().setToLife(LD.nGOOD_NOTE_VALUE);
  432.             _mcPowerUp.swapDepths(7777);
  433.             _mcPowerUp.removeMovieClip();
  434.       }
  435.    }
  436.    function winGame()
  437.    {
  438.       CTRLGame.getRef().Screen.getInterface().pauseTime();
  439.       Main.getRef().winGame();
  440.    }
  441.    function loseGame()
  442.    {
  443.       CTRLGame.getRef().Screen.getInterface().pauseTime();
  444.       Main.getRef().loseGame();
  445.    }
  446.    function initLevel()
  447.    {
  448.       this.aItems = [[],[],[],[],[],[],[],[],[],[]];
  449.       this.aWalls = new Array();
  450.       this.aAlguaes = [[],[],[],[],[],[],[],[],[],[]];
  451.       this.aDirtWalls = [[],[],[],[],[],[],[],[],[],[]];
  452.       this.aJellys = new Array();
  453.       this.nNbPushBusSandyLeft = LD.nNB_PUSHBUS_WITH_SANDY;
  454.       this.nSongsNumber = LD.getSongsMax(this.nCurrentLevel);
  455.       this.oGenerator = new MazeGenerator(this.mcRef);
  456.       this.oCenterScreen = new CenterScreen(this.mcRef.mcCenter);
  457.       this.oGenerator.generate();
  458.       this.oAtlantisBus = new AtlantisBus();
  459.    }
  460. }
  461.